<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>系统管理-角色管理</title>

    <link href="../plugin/bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-table-1.11.1/bootstrap-table.min.css" rel="stylesheet"/>
    <link href="../plugin/sweetalert-6.6.2/sweetalert2.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-3.3.7/plugin/file_input/fileinput.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.min.css" rel="stylesheet"/>
    <link href="../plugin/jquery-zoomify/zoomify.min.css" rel="stylesheet"/>
    <link href="../plugin/jstree/jstree.min.css" rel="stylesheet">

    <script src="../plugin/jquery-3.2.1/jquery-3.2.1.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/js/bootstrap.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/file_input/fileinput.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/file_input/local_zh.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="../plugin/bootstrap-table-1.11.1/bootstrap-table.min.js"></script>
    <script src="../plugin/bootstrap-table-1.11.1/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="../plugin/sweetalert-6.6.2/sweetalert2.min.js"></script>
    <script src="../plugin/jquery-3.2.1/jquery.formautofill.min.js"></script>
    <script src="../plugin/jquery-zoomify/zoomify.min.js"></script>
    <script src="../plugin/jquery-3.2.1/jquery.serializejson.js"></script>
    <script src="../plugin/soul/utils3.js"></script>
    <script src='../base/base.js'></script>
    <script src="../plugin/jstree/jstree.min.js"></script>
</head>

<body>
<div class="modal fade" data-backdrop="static" id="role_privilege_edit_modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
                <h4 class="modal-title">
                    <b>角色权限编辑</b>
                </h4>
            </div>
            <div class="modal-body">
                <form id="role_privilege_edit_form" method="post">
                    <div class="form-group">
                        <label>权限列表</label>
                        <div id="role_privilege_edit_form_privIds"></div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">取消</button>
                <button class="btn btn-primary" onclick="role.privilege.save()">保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        var resp = AjaxUtil.isLogin();
        if (!resp) return;
        var module = 'role';// 评价模块
        var query = [{
            id: 'name',
            type: 'text',
            name: '角色名称',
            paramName:'name',
            palceholder:''
        }];
        var toolbar = {
            default: [false, true, true, true],// back;add;edit;remove
            dialog: [50, 2, 9],//对话框参数:模态框宽度(百分比);表单标题宽度;表单输入框宽度
            extra: [{
                name: '编辑用户权限',
                onclick: 'showRolePrivilegeModal'
            }]
        };
        var formElement = [{
            action: [false, true],
            type: 'hidden', // 表单类型
            name: 'roleId', // 字段名称
        }, {
            action: [true, true],
            type: 'text',
            label: '角色名称',
            name: 'name',
        }];

        var bootstrapTable = {
            url: '',
            columns: [{
                radio: true
            }, {
                field: 'roleId',
                title: '角色编号',
                align: 'center',
            }, {
                field: 'name',
                title: '角色名称',
                align: 'center',
            }, {
                field: 'privJson',
                title: '权限明细',
                align: 'center',
                formatter: function (value, row, index){
                    if(row.roleId == 1){
                        return '所有权限';
                    }
                    var privJson = JSON.parse(value);
                    var priv = '';
                    for (i in privJson){
                        if(privJson[i].parentId == null){
                            priv += privJson[i].name + ','
                        }
                    }
                    if(priv.length>0){
                        priv = priv.substring(0,priv.length-1);
                    } else {
                        priv = '无';
                    }
                    return priv;
                }
            }]
        }

        // debugger;
        role = SingleTablePageCreateUtil.createInstance(module, query, toolbar, formElement, bootstrapTable);
        role.showRolePrivilegeModal = function () {
            var row = TablePageCreatePublicUtil.getRowFromTable('#role_table');
            if (!row) return false;
            role.privilege.currentRoleId = row.roleId;
            var resp = AjaxUtil.getJson('privilege/list');
            if (!resp) return false;
            var jsTreeData = JsTreeUtil.createPrivTree('#role_privilege_edit_form_privIds',resp.obj, row.privIds);
            $('#role_privilege_edit_modal').modal('show');
        };
        role.privilege = {};
        role.privilege.save = function () {
            var rolePrivIds = JsTreeUtil.getCheck('#role_privilege_edit_form_privIds');
            var resp = AjaxUtil.postJson('role/editPriv', {
                roleId: role.privilege.currentRoleId,
                privIds: rolePrivIds
            });
            if (resp) {
                SwalUtil.success(resp.msg);
                $('#role_table').bootstrapTable('refresh');
                $('#privilege_table').bootstrapTable('refresh');
                $('#role_privilege_edit_modal').modal('hide');
            }
        };
    });
</script>
</body>

</html>